﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOOL_S01_EP02
{
    public class LogDataSummary
    {
        public List<string> CmdSendedList;
        public List<string> KfkSendedList;
        public Dictionary<string, string> BuscodeTerminalKey;

        public LogDataSummary()
        {
            Initializing();
        }

        public LogDataSummary(string _filename)
        {
            Initializing();
            SumUp(_filename);
        }

        public LogDataSummary(string[] _filenames)
        {
            Initializing();
            foreach (string _filename in _filenames)
            {
                SumUp(_filename);
            }
        }

        public void Initializing()
        {
            BuscodeTerminalKey = new Dictionary<string, string>();
            CmdSendedList = new List<string>();
            KfkSendedList = new List<string>();
        }

        public void SumUp(string _filename)
        {
            string _temp;
            StreamReader _streamReader = new StreamReader(_filename);         

            while ((_temp = _streamReader.ReadLine()) != null)
            {
                if (_temp.Contains("CommandSend"))
                {
                    CmdSendedList.Add(_temp);
                    Boxin(_temp);
                }
                else if (_temp.Contains("KafkaSend"))
                {
                    KfkSendedList.Add(_temp);
                }
                else {
                    continue;
                }
            }

            CmdSendedList = CmdSendedList.Distinct().ToList();
            //KfkSendedList = KfkSendedList.Distinct().ToList();
        }

        public void Boxin(string _line)
        {
            string[] _strArray = _line.Split(',');
            string foo = _strArray[1].Substring(8);
            string bar = _strArray[4].Substring(12);
            BuscodeTerminalKey[_strArray[1].Substring(8)] = _strArray[4].Substring(12);
        }
    }
}
